app.service('shopDetailEditService',['$q','utilService',function($q,utilService){
    var _this_=this;
    _this_.shopEditVO={
        bannerImages:[]
    };

    //查询店铺信息
    _this_.findinfo= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/id'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //修改商品
    _this_.updateShop=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"/shop/edit",
            data:_this_.shopEditVO,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //删除商品头像
    _this_.delShopHeaderImages=function($scope,url){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"/shop/head/img",
            data:{shopHeadImgUrl:url},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //删除背景图片
    _this_.delBackgroundImage=function($scope,url){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"/shop/background/image",
            data:{shopHeadImgUrl:url},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //删除商品广告图
    _this_.delBannerImages=function($scope,url){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"/shop/banner/img",
            data:{bannerImage:url},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }



    _this_.findArea=function($scope,level,parentId){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain+"/area/info",
            params:{level:level,parentId:parentId}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

}])